<template>
  <section>
    <div class="flex-row">
      <div class="flex-item-fixed mr10">
        <div class="preview-layer">
          <div class="preview-bg"></div>
          <div class="preview-phone">
            <div class="preview-content">
              <div class="top-video">

                <video-player  class="video-player-box"
                               ref="videoPlayer"
                               :options="playerOptions"
                               :playsinline="true"
                               @ready="playerReadied" v-if="currentKnowledge.video">
                </video-player>
                <template v-else>
                  <image-cover v-if="currentKnowledge.cover" :thumb.sync="currentKnowledge.cover" width="361px" height="241px" size-type="contain"></image-cover>
                </template>
              </div>

              <div class="article-title">
                <h1 class="title">{{currentKnowledge.title}}</h1>
              </div>
              <div class="article-provide">
                <span>{{currentKnowledge.provider}}</span>
              </div>
              <div class="article-content">
                <html-content :contentHtml="currentKnowledge.content"></html-content>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="flex-item-fixed preview-right">
        <el-col class="pd5" v-if="currentKnowledge.status===3||currentKnowledge.status===2||currentKnowledge.status===1">
          <el-button type="primary"  plain @click="save(2)">提交审核</el-button>
        </el-col>
        <el-col class="pd5" v-if="currentKnowledge.status===4" v-has="{class:'knowledge:pass'}">
          <el-button type="success"  plain @click="save(4)">审核通过</el-button>
        </el-col>
        <el-col class="pd5" v-if="currentKnowledge.status===4" v-has="{class:'knowledge:reject'}">
          <el-button type="info"  plain @click="save(5)">驳回</el-button>
        </el-col>
        <el-col class="pd5" v-if="currentKnowledge.status===3" v-has="{class:'knowledge:publish'}">
          <el-button type="info" plain @click="save(3)">发布</el-button>
        </el-col>
        <el-col class="pd5" v-if="currentKnowledge.status===5" v-has="{class:'knowledge:down'}">
          <el-button type="danger" plain @click="save(6)">下架</el-button>
        </el-col>
        <el-col class="pd5" v-if="currentKnowledge.status===1" v-has="{class:'knowledge:up'}">
          <el-button type="danger" plain @click="save(7)">上架</el-button>
        </el-col>
      </div>
    </div>
  </section>
</template>

<script>
import { mapGetters } from "vuex";
import ImageCover from "@/components/image-cover";
import HtmlContent from "@/components/html-content";
export default {
  name: "pre-knowledge",
  props: {
    isClose: Boolean
  },
  created() {},
  mounted() {},
  computed: {
    ...mapGetters({
      currentKnowledge: "currentKnowledge",
      playerOptions: "playerOptions"
    })
  },
  data() {
    return {};
  },
  methods: {
    // player is ready
    playerReadied(player) {
      var obj = {};
      obj.poster = this.$options.filters.fullImagePath(
        this.currentKnowledge.cover
      );
      obj.src = this.$options.filters.fullImagePath(
        this.currentKnowledge.video
      );
      this.$store.dispatch("updateVideoOptions", obj).then(ret => {});
    },
    back() {
      this.$emit("close");
    },
    save(status) {
      this.currentKnowledge.opt = status;
      this.$store
        .dispatch("addOrUpdateKnowledgeS", this.currentKnowledge)
        .then(ret => {
          this.$notify({
            title: "提交成功",
            type: "success"
          });
          this.back();
        });
    }
  },
  components: {
    ImageCover,
    HtmlContent
  }
};
</script>

<style scoped>
@import "../../../../src/styles/preview-style.css";

.right {
  text-align: left;
  width: 100px;
  margin-top: 100px;
  vertical-align: middle;
}

.pd5 {
  padding: 5px;
}
.top-video {
}
.content {
  background: white;
  position: absolute;
  top: 99px;
  left: 25px;
  width: 361px;
  height: 638px;
  overflow-y: scroll;
  padding-top: 5px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  word-break: normal;
  overflow-x: hidden;
}
</style>
